export default {
  namespaced: true, // 开启命名空间
  state: {
    // 存放状态
    categoryList:
      localStorage.getItem("categoryList") !== ""
        ? JSON.parse(localStorage.getItem("categoryList"))
        : [],
  },
  getters: {
    // 计算属性
  },
  mutations: {
    // 定义修改状态的方法
    setCategoryList(state, value) {
      state.categoryList = value;
      localStorage.setItem("categoryList", JSON.stringify(value));
    },
  },
  actions: {
    // 定义异步方法
    updateCategoryList({ commit }) {
      commit("setCategoryList", [
        { id: 1, title: "学习笔记", backgroundColor: "gold" },
        { id: 2, title: "个人项目", backgroundColor: "purple" },
        { id: 3, title: "随心记", backgroundColor: "pink" },
      ]);
    },
  },
};
